//
//  HZPanKouView.m
//  HZTC_Stock
//
//  Created by MayerF on 17/3/14.
//  Copyright © 2017年 MayerF. All rights reserved.
//

#import "HZPanKouView.h"

#define kPanKouMargin 5
#define kPanKouPadding 10

@interface HZPanKouView()
@property (nonatomic, strong)NSMutableArray *pTitleLabelArray;
@property (nonatomic, strong)NSMutableArray *pContentLabelArray;
@end

@implementation HZPanKouView
- (NSMutableArray *)pTitleLabelArray
{
    if (!_pTitleLabelArray) {
        _pTitleLabelArray = [NSMutableArray arrayWithCapacity:10];
    }
    return _pTitleLabelArray;
}
- (NSMutableArray *)pContentLabelArray
{
    if (!_pContentLabelArray) {
        _pContentLabelArray = [NSMutableArray arrayWithCapacity:10];
    }
    return _pContentLabelArray;
}
#pragma mark -
#pragma mark 生命周期
- (instancetype)init{
    self = [super init];
    if (self) {
        [self p_commonInit];
        self.backgroundColor = [UIColor whiteColor];
    }
    return self;
}

- (void)layoutSubviews{
    CGFloat fItemW = (CGRectGetWidth(self.frame) - 2*kPanKouMargin - 2*kPanKouPadding)/6;
    CGFloat fItemH = CGRectGetHeight(self.frame)/5;
    for (int i = 0; i < _pTitleLabelArray.count; i++) {
        UILabel *title = _pTitleLabelArray[i];
        UILabel *content = _pContentLabelArray[i];
        CGFloat Y = fItemH * (i/3);
        CGFloat titleX = kPanKouMargin + (fItemW*2+kPanKouPadding) * (i%3);
        CGFloat contentX = kPanKouMargin + fItemW + (fItemW*2+kPanKouPadding) * (i%3);
        title.frame = CGRectMake(titleX, Y, fItemW, fItemH);
        content.frame = CGRectMake(contentX, Y, fItemW, fItemH);
    }
}
#pragma mark -
#pragma mark private
- (void)p_commonInit
{
    NSArray *pTitleArray = [NSArray arrayWithObjects:
                            @"平均价",
                            @"涨停",
                            @"跌停",
                            kHZChengJiaoLiang,
                            kHZNeiPan,
                            kHZWaiPan,
                            kHZChengJiaoE,
                            kHZWeiBi,
                            kHZWeiCha,
                            kHZHuanShouLV,
                            @"振幅",
                            @"现手",
                            @"市盈率",
                            kHZLiangBi,nil];
    
    for (NSString *title in pTitleArray) {
        UILabel *pTitle = [UILabel new];
        UILabel *pContent = [UILabel new];
        pTitle.text = title;
        pContent.text = kDefaultContent;
        pContent.textAlignment = NSTextAlignmentRight;
        pTitle.textColor = kMYHexToRGB(0x6b6b6b, 1);
        pTitle.font = pContent.font = [UIFont systemFontOfSize:13];
        [self addSubview:pTitle];
        [self addSubview:pContent];
        [self.pTitleLabelArray addObject:pTitle];
        [self.pContentLabelArray addObject:pContent];
    }
}
#pragma mark -
#pragma mark public
- (void)updateNewData:(HZMinPriceModel *)data
{
    NSArray *pTempArray = [NSArray arrayWithObjects:
                           data.model_avgPrice,
                           data.model_zhangTing,
                           data.model_dieTing,
                           data.model_chengJiaoLiang,
                           data.model_inPan,
                           data.model_outPan,
                           data.model_chengJiaoE,
                           data.model_weiBi,
                           data.model_weiCha,
                           data.model_huanShouLv,
                           data.model_zhangFu,
                           data.model_currentNum,
                           data.model_shiYing,
                           data.model_liangBi,nil];
    
    for (int i = 0; i < pTempArray.count; i++) {
        NSString *pContent = pTempArray[i];
        UILabel *pContentLabel = _pContentLabelArray[i];
        pContentLabel.text = pContent;
        pContentLabel.adjustsFontSizeToFitWidth = YES;
        if (i == 0) {
            if ([data.model_avgPrice floatValue] > [data.model_prePrice floatValue]) {
                pContentLabel.textColor = kREDColor;
            }else if ([data.model_avgPrice floatValue] < [data.model_prePrice floatValue]) {
                pContentLabel.textColor = kGREENColor;
            }else {
                pContentLabel.textColor = [UIColor blackColor];
            }
        }else if (i == 1) {
            pContentLabel.textColor = kREDColor;
        }else if (i == 2) {
            pContentLabel.textColor = kGREENColor;
        }
    }
}

@end
